package com.foreknow.demo9;

/**
 * @author shkstart
 * @create 2021-07-29 10:50
 */
public class UserManager {
    String[] name =new String[2];
    String[] pass =new String[2];

    public  void  register(String username,String password)throws  CustomException{
        //查看字符串长度
        int nameLength  = username.length();
        int passLength = password.length();
        //校验用户名和面是否为空
        if(username.equals("") ||password.equals("")){
            //抛出异常
            throw new CustomException("用户名或密码为空");
        }

        if(username.length()<6||username.length()>10){
            throw  new CustomException("用户名长度不规范");
        }
        if(password.length()<6||password.length()>10){
            throw  new CustomException("密码长度不规范");
        }
        for (int i = 0; i < name.length; i++) {
            if(name[i]==null&&pass[i]==null){
                name[i]=username;
                pass[i]=password;
                System.out.println("注册成功");
            }
        }
        throw new CustomException("用户已达上限，无法注册...");
    }


    public static void main(String[] args) {
        UserManager userManager=new UserManager();

        try {
            userManager.register("","");
//            userManager.register("asdasdaasd","asdasda");

            userManager.register("asd","asd");
        } catch (CustomException e) {
            e.printStackTrace();
        }
        System.out.println("继续执行");
    }
}
